{
    var director_item=document.getElementsByClassName('director_item');
    var temp=0;
    var cn1=0;
    var cn2=0;
    var cn3=true;
    var wrapper=document.getElementsByClassName('wrapper');
    var banner_item=document.getElementsByClassName('banner_item');
    var history1=document.getElementById('history1');
    var history2=document.getElementById('history2');
    var tb_wrapper1=document.getElementsByClassName('tb_wrapper1');
    var tb_wrapper2=document.getElementsByClassName('tb_wrapper2');
    var search1=document.getElementById('search1');
    var search2=document.getElementById('search2');
    var name1=document.getElementById('name1');
    var name2=document.getElementById('name2');
    var user1,user2,user3,user4;//请假用户对象数组、调研学用户对象数组
    var f1=document.getElementById('f1');
    var f2=document.getElementById('f2');
    var f3=document.getElementById('f3');
    var f4=document.getElementById('f4');
    var f5=document.getElementById('f5');
    var f6=document.getElementById('f6');
    var f7=document.getElementById('f7');
    var avatar=document.getElementById('avatar');
    var user_event=document.getElementById('user_event');
    var whole_wrapper=document.getElementById('whole_wrapper');
}
//初始化
director_item[temp].style.backgroundColor='#2F4399';
banner_item[temp].style.display='block';
tb_wrapper1[0].style.display='block';
tb_wrapper2[0].style.display='block';
document.getElementById("director").addEventListener("click",(event)=>{
    if([...director_item].includes(event.target)){
        temp_1=temp;
        director_item[temp].style.backgroundColor='transparent';
        banner_item[temp].style.display='none';
        if(temp!==0){
            wrapper[temp-1].style.opacity=0;
        }
        event.target.style.backgroundColor='#2F4399';
        temp=[...director_item].indexOf(event.target);
        banner_item[temp].style.display='block';
        switch (temp) {
            case 0:
                whole_wrapper.style.background = 'url(./image/background1.png)';
                break;
            case 1:
                whole_wrapper.style.background = 'url(./image/background2.png)';
                break;
            case 2:
                whole_wrapper.style.background = 'url(./image/background3.png)';
                break;
        }
        if(temp!==0){
            setTimeout(()=>{wrapper[temp-1].style.opacity=1;},100);
        }
    }
});
//今日请假
function draw_table1(info,i){
    info.insertAdjacentHTML('beforeend',`<tr>
                <td><div class="table_box1">${user1[i].name}</div></td>
                <td><div class="table_box1">${user1[i].direction}</div></td>
                <td><div class="table_box1">${user1[i].term}</div></td>
                <td><div class="table_box1">第${user1[i].leave_class}节</div></td>
                <td><div class="table_box2">${user1[i].reason}</div></td>
                </tr>`);
}
//本周请假
function draw_table2(info,i,user){
    info.insertAdjacentHTML('beforeend',`<tr>
                <td><div class="table_box1">${user[i].name}</div></td>
                <td><div class="table_box1">${user[i].direction}</div></td>
                <td><div class="table_box1">${user[i].term}</div></td>
                <td><div class="table_box3">
                        <div class="table_box3_child1">${user[i].leave_date}</div>
                        <div class="table_box3_child2">第${user[i].leave_class}节</div>
                    </div></td>
                <td><div class="table_box2">${user[i].reason}</div></td>
                </tr>`);
}
//今日调整
function draw_table3(info,i){
    info.insertAdjacentHTML('beforeend',`<tr>
                <td><div class="table_box1">${user2[i].name}</div></td>
                <td><div class="table_box1">${user2[i].direction}</div></td>
                <td><div class="table_box1">${user2[i].term}</div></td>
                <td><div class="table_box1">第${user2[i].leave_class}节</div></td>
                <td><div class="table_box1">第${user2[i].adjust_class}节</div></td>
                <td><div class="table_box2">${user2[i].reason}</div></td>
                </tr>`);
}
//本周调整
function draw_table4(info,i,user){
    info.insertAdjacentHTML('beforeend',`<tr>
                <td><div class="table_box1">${user[i].name}</div></td>
                <td><div class="table_box1">${user[i].direction}</div></td>
                <td><div class="table_box1">${user[i].term}</div></td>
                <td><div class="table_box3">
                        <div class="table_box3_child1">${user[i].leave_date}</div>
                        <div class="table_box3_child2">第${user[i].leave_class}节</div>
                    </div></td>
                <td><div class="table_box3">
                        <div class="table_box3_child1">${user[i].adjust_date}</div>
                        <div class="table_box3_child2">第${user[i].adjust_class}节</div>
                    </div></td>
                <td><div class="table_box2">${user[i].reason}</div></td>
                </tr>`);
}
function rmtb(obj){
    if(obj.length!==0){
        for(let i=0;i<obj.length;i++){
            let li=obj[0].getElementsByTagName('tbody');
            while(li.length!==0){
                li[0].remove();
            }
        }
    }
}
//渲染数据 获取服务器数据
axios({
    method:"post",
    url:"http://jp-tyo-ntt-1.natfrp.cloud:42782/Study_Leave_System/condition_LeaveServlet",
    headers:{
        "Content-type":"application/json"
    }
}).then(response=>{
    console.log(response);
    user1=response.data.data;
    for(let i=0;i<user1.length;i++){
        let info=tb_wrapper1[0].getElementsByTagName('table');
        draw_table1(info[0],i);
    }
}).catch(error=>{
    console.log(error);
});
axios({
    method:"post",
    url:"http://jp-tyo-ntt-1.natfrp.cloud:42782/Study_Leave_System/condition_AdjustServlet",
    headers:{
        "Content-type":"application/json"
    }
}).then(response=>{
    console.log(response);
    user2=response.data.data;
    for(let i=0;i<user2.length;i++){
        let info=tb_wrapper2[0].getElementsByTagName('table');
        draw_table3(info[0],i);
    }
}).catch(error=>{
    console.log(error);
});
axios({
    method:"post",
    url:"http://jp-tyo-ntt-1.natfrp.cloud:43130/study__leave__system_war_exploded/ShowLeaveServlet",
    headers:{
        "Content-type":"application/json"
    }
}).then(response=>{
    console.log(response);
    user3=response.data.data;
}).catch(error=>{
    console.log(error);
});
axios({
    method:"post",
    url:"http://jp-tyo-ntt-1.natfrp.cloud:43130/study__leave__system_war_exploded/ShowAdjustServlet",
    headers:{
        "Content-type":"application/json"
    }
}).then(response=>{
    console.log(response);
    user4=response.data.data;
}).catch(error=>{
    console.log(error);
});
history1.onclick=()=>{
    let head=document.getElementById('head1');
    if(cn1===0){
        head.innerText='本周请假';
        history1.innerText='今日请假';
        rmtb(tb_wrapper1[0].getElementsByTagName('table'));
        for(let i=0;i<user3.length;i++){
            draw_table2(tb_wrapper1[0].getElementsByTagName('table')[0],i,user3);
        }
        cn1=1;
    }else{
        head.innerText='今日请假';
        history1.innerText='本周历史';
        rmtb(tb_wrapper1[0].getElementsByTagName('table'));
        for(let i=0;i<user1.length;i++){
            draw_table1(tb_wrapper1[0].getElementsByTagName('table')[0],i);
        }
        cn1=0;
    }
};
history2.onclick=()=>{
    let head=document.getElementById('head2');
    if(cn2===0){
        head.innerText='本周调整';
        history2.innerText='今日调整';
        rmtb(tb_wrapper2[0].getElementsByTagName('table'));
        for(let i=0;i<user4.length;i++){
            draw_table4(tb_wrapper2[0].getElementsByTagName('table')[0],i,user4);
        }
        cn2=1;
    }else{
        head.innerText='今日调整';
        history2.innerText='本周历史';
        rmtb(tb_wrapper2[0].getElementsByTagName('table'));
        for(let i=0;i<user2.length;i++){
            draw_table3(tb_wrapper2[0].getElementsByTagName('table')[0],i);
        }
        cn2=0;
    }
};
search1.onclick=()=>{
    let a=name1.value.trim();
    rmtb(tb_wrapper1[0].getElementsByTagName('table'));
    search1.setAttribute('disabled',true);
    axios({
        method:"post",
        url:"http://jp-tyo-ntt-1.natfrp.cloud:42782/Study_Leave_System/students_LeaveServlet",
        headers:{
            "Content-type":"application/json"
        },
        data:{
            name:a
        }
    }).then(response=>{
        console.log(response);
        for(let i=0;i<response.data.data.length;i++){
            let info=tb_wrapper1[0].getElementsByTagName('table');
            info[0].insertAdjacentHTML('beforeend',`<tr>
                    <td><div class="table_box1">${a}</div></td>
                    <td><div class="table_box1">${response.data.data[i].direction}</div></td>
                    <td><div class="table_box1">${response.data.data[i].term}</div></td>
                    <td><div class="table_box3">
                            <div class="table_box3_child1">${response.data.data[i].leave_date}</div>
                            <div class="table_box3_child2">第${response.data.data[i].leave_class}节</div>
                        </div></td>
                    <td><div class="table_box2">${response.data.data[i].reason}</div></td>
                    </tr>`);
            search1.removeAttribute('disabled');
        }
    }).catch(error=>{
        search1.removeAttribute('disabled');
        console.log(error);
    });
};
search2.onclick=()=>{
    let a=name2.value.trim();
    rmtb(tb_wrapper2[0].getElementsByTagName('table'));
    search2.setAttribute('disabled',true);
    axios({
        method:"post",
        url:"http://jp-tyo-ntt-1.natfrp.cloud:42782/Study_Leave_System/students_AdjustServlet",
        headers:{
            "Content-type":"application/json"
        },
        data:{
            name:a
        }
    }).then(response=>{
        console.log(response);
        for(let i=0;i<response.data.data.length;i++){
            let info=tb_wrapper2[0].getElementsByTagName('table');
            info[0].insertAdjacentHTML('beforeend',`<tr>
                    <td><div class="table_box1">${a}</div></td>
                    <td><div class="table_box1">${response.data.data[i].direction}</div></td>
                    <td><div class="table_box1">${response.data.data[i].term}</div></td>
                    <td><div class="table_box3">
                            <div class="table_box3_child1">${response.data.data[i].leave_date}</div>
                            <div class="table_box3_child2">第${response.data.data[i].leave_class}节</div>
                        </div></td>
                    <td><div class="table_box3">
                            <div class="table_box3_child1">${response.data.data[i].adjust_date}</div>
                            <div class="table_box3_child2">第${response.data.data[i].adjust_class}节</div>
                        </div></td>
                    <td><div class="table_box2">${response.data.data[i].reason}</div></td>
                    </tr>`);
            search2.removeAttribute('disabled');
        }
    }).catch(error=>{
        search2.removeAttribute('disabled');
        console.log(error);
    });
};
f1.flag=true;f2.flag=true;f3.flag=true;f4.flag=true;f5.flag=true;f6.flag=true;f7.flag=true;
f1.onchange=function(){
    rmtb(tb_wrapper1[0].getElementsByTagName('table'));
    f1.flag=false;
    for(let i=0;i<user3.length;i++){
        if((f1.flag||user3[i].direction===f1.options[f1.selectedIndex].value)&&(f2.flag||user3[i].term==f2.options[f2.selectedIndex].value)&&(f3.flag||user3[i].leave_class===f3.options[f3.selectedIndex].value)){
            if(cn1===0){
                draw_table1(tb_wrapper1[0].getElementsByTagName('table')[0],i);
            }else{
                draw_table2(tb_wrapper1[0].getElementsByTagName('table')[0],i,user3);
            }
        }
    }
}
f2.onchange=function(){
    rmtb(tb_wrapper1[0].getElementsByTagName('table'));
    f2.flag=false;
    for(let i=0;i<user3.length;i++){
        if((f1.flag||user3[i].direction===f1.options[f1.selectedIndex].value)&&(f2.flag||user3[i].term==f2.options[f2.selectedIndex].value)&&(f3.flag||user3[i].leave_class===f3.options[f3.selectedIndex].value)){
            if(cn1===0){
                draw_table1(tb_wrapper1[0].getElementsByTagName('table')[0],i);
            }else{
                draw_table2(tb_wrapper1[0].getElementsByTagName('table')[0],i,user3);
            }
        }
    }
}
f3.onchange=function(){
    rmtb(tb_wrapper1[0].getElementsByTagName('table'));
    f3.flag=false;
    for(let i=0;i<user3.length;i++){
        if((f1.flag||user3[i].direction===f1.options[f1.selectedIndex].value)&&(f2.flag||user3[i].term==f2.options[f2.selectedIndex].value)&&(f3.flag||user3[i].leave_class===f3.options[f3.selectedIndex].value)){
            if(cn1===0){
                draw_table1(tb_wrapper1[0].getElementsByTagName('table')[0],i);
            }else{
                draw_table2(tb_wrapper1[0].getElementsByTagName('table')[0],i,user3);
            }
        }
    }
}
f4.onchange=function(){
    rmtb(tb_wrapper2[0].getElementsByTagName('table'));
    f4.flag=false;
    for(let i=0;i<user4.length;i++){
        if((f4.flag||user4[i].direction===f4.options[f4.selectedIndex].value)&&(f5.flag||user4[i].term==f5.options[f5.selectedIndex].value)&&(f6.flag||user4[i].leave_class===f6.options[f6.selectedIndex].value)&&(f7.flag||user4[i].adjust_class===f7.options[f7.selectedIndex].value)){
            if(cn2===0){
                draw_table3(tb_wrapper2[0].getElementsByTagName('table')[0],i);
            }else{
                draw_table4(tb_wrapper2[0].getElementsByTagName('table')[0],i,user4);
            }
        }
    }
}
f5.onchange=function(){
    rmtb(tb_wrapper2[0].getElementsByTagName('table'));
    f5.flag=false;
    for(let i=0;i<user4.length;i++){
        if((f4.flag||user4[i].direction===f4.options[f4.selectedIndex].value)&&(f5.flag||user4[i].term==f5.options[f5.selectedIndex].value)&&(f6.flag||user4[i].leave_class===f6.options[f6.selectedIndex].value)&&(f7.flag||user4[i].adjust_class===f7.options[f7.selectedIndex].value)){
            if(cn2===0){
                draw_table3(tb_wrapper2[0].getElementsByTagName('table')[0],i);
            }else{
                draw_table4(tb_wrapper2[0].getElementsByTagName('table')[0],i,user4);
            }
        }
    }
}
f6.onchange=function(){
    rmtb(tb_wrapper2[0].getElementsByTagName('table'));
    f6.flag=false;
    for(let i=0;i<user4.length;i++){
        if((f4.flag||user4[i].direction===f4.options[f4.selectedIndex].value)&&(f5.flag||user4[i].term==f5.options[f5.selectedIndex].value)&&(f6.flag||user4[i].leave_class===f6.options[f6.selectedIndex].value)&&(f7.flag||user4[i].adjust_class===f7.options[f7.selectedIndex].value)){
            if(cn2===0){
                draw_table3(tb_wrapper2[0].getElementsByTagName('table')[0],i);
            }else{
                draw_table4(tb_wrapper2[0].getElementsByTagName('table')[0],i,user4);
            }
        }
    }
}
f7.onchange=function(){
    rmtb(tb_wrapper2[0].getElementsByTagName('table'));
    f7.flag=false;
    for(let i=0;i<user4.length;i++){
        if((f4.flag||user4[i].direction===f4.options[f4.selectedIndex].value)&&(f5.flag||user4[i].term==f5.options[f5.selectedIndex].value)&&(f6.flag||user4[i].leave_class===f6.options[f6.selectedIndex].value)&&(f7.flag||user4[i].adjust_class===f7.options[f7.selectedIndex].value)){
            if(cn2===0){
                draw_table3(tb_wrapper2[0].getElementsByTagName('table')[0],i);
            }else{
                draw_table4(tb_wrapper2[0].getElementsByTagName('table')[0],i,user4);
            }
        }
    }
}
avatar.onclick=function(){
    if(cn3){
        user_event.style.display='block';
        cn3=false;
    }else{
        user_event.style.display='none';
        cn3=true;
    }
};
user_event.onclick=()=>{
    window.location='../登录注册页面/2022-2023寒假项目实战2.0/首页2.0.html';
};